/*
 * Copyright (c) 2012 Robert Burrell Donkin robertburrelldonkin.name
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 
 * is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */
package walrus.text.wiki.micro;

public class WikiTracker {

	private boolean inTitle;
	private boolean inCurly;
	private boolean inSquare;
	private int parameterNumber;
	private boolean inList;

	public WikiTracker() {
		reset();
	}

	public void reset() {
		inTitle = false;
		inCurly = false;
		inSquare = false;
	}

	public void next(final WikiState state) {
		switch (state) {
		case CLOSE_CURLY:
			inCurly = false;
			parameterNumber = 0;
			break;
		case OPEN_CURLY:
			inCurly = true;
			break;
		case TITLE:
		case SUBTITLE:
		case SUBSUBTITLE:
		case SUB3TITLE:
		case SUB4TITLE:
			inTitle = !inTitle;
			break;
		case OPEN_SQUARE:
			inSquare = true;
			break;
		case CLOSE_SQUARE:
			parameterNumber = 0;
			inSquare = false;
			break;
		case PIPE:
			parameterNumber++;
			break;
		case HASH:
		case STAR:
			inList = true;
			break;
		case EMPTY_LINE:
			inList = false;
			break;
		}
	}

	public boolean isInTitle() {
		return inTitle;
	}

	public boolean isInCurly() {
		return inCurly;
	}

	public boolean isInSquare() {
		return inSquare;
	}

	public int getParameterNumber() {
		return parameterNumber;
	}

	public boolean isInList() {
		return inList;
	}

	@Override
	public String toString() {
		return "WikiTracker [inCurly=" + inCurly + ", inList=" + inList
				+ ", inSquare=" + inSquare + ", inTitle=" + inTitle
				+ ", parameterNumber=" + parameterNumber + "]";
	}
	
	
}
